<template>
	<view class="u-modal f-bdr-base" :class="[show ? 'z-show' : '']">
		<view class="u-dialog f-oh">
			<view class="g-title f-por" v-if="title">
				<view class="g-title-content f-tac f-fz16 f-fc-primary">{{ title }}</view>
			</view>
			<view class="g-content">{{ content }}</view>
			<view class="g-btn-view f-frow">
				<button class="u-btn" @tap="cancel">{{ cancelTxt }}</button>
				<button class="u-btn btn-red" @tap="confirm">{{ confirmTxt }}</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		custom: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			show: false,
			title: '',
			content: '',
			cancelTxt: '',
			confirmTxt: '',
			success: null
		};
	},
	methods: {
		/**
		 * @method showModal
		 * @param {String} title		modal标题，非必传
		 * @param {String} content  	modal内容，必传
		 * @param {String} cancelTxt	关闭文字，非必传
		 * @param {String} confirmTxt	确认文字，非必传
		 * @param {String} success		处理函数，必传
		 * */
		showModal({ title, content, cancelTxt = '取消', confirmTxt = '确认', success }) {
			const that = this;
			that.title = title;
			that.content = content;
			that.cancelTxt = cancelTxt;
			that.confirmTxt = confirmTxt;
			that.success = success;
			that.show = true;
		},

		/**
		 * @method confirm
		 * */
		confirm() {
			const that = this;
			that.show = false;
			that.success({
				confirm: true
			});
		},

		/**
		 * @method cancel
		 * */
		cancel() {
			const that = this;
			that.show = false;
			that.success({
				confirm: false
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.g-title {
	height: 100rpx;
	.g-title-content {
		width: calc(100vw - 340rpx);
		height: 100rpx;
		line-height: 100rpx;
		margin: auto;
		font-size: 36rpx;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
	}
}
.g-content {
	padding: 50rpx;
	font-size: 32rpx;
}

.g-btn-view {
	.u-btn {
		width: 50%;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		border-top: 2rpx solid #e3e3e3;
		border-radius: 0;
		font-size: 32rpx;
		color: $uni-text-color;
	}
	.u-btn.button-hover {
		opacity: 0.7;
		background-color: none;
	}
	.btn-red {
		color: #ff0000;
		border-left: 2rpx solid #e3e3e3;
	}
}

.u-close {
	width: 100rpx;
	height: 100rpx;
	position: absolute;
	top: 0;
	right: 0;
}
</style>
